import axios from 'axios'
import { CONST_DMOMAIN_URL } from "@/config/env";

const instance = axios.create({
    baseURL: CONST_DMOMAIN_URL,
})

instance.interceptors.request.use(
    config => {
        let token = sessionStorage.getItem('token')
        if (token) {
            config.headers["Authorization"] = token
        }
        return config
    }, error => {
        return Promise.reject(error)
    })

instance.interceptors.response.use(
    response => {
        if (response.data.code == 1000) {
            sessionStorage.removeItem('token')
            response.sendRedirect("/")
        }
        return response
    }, error => {
        return Promise.reject(error)
    })

export default instance;